/***************************************************************
Made by: Cultured::Labs

Copyright (c) 2010 Cultured::Labs
****************************************************************/
/////////////////////////////////////////////////////////////////
//Description:                                                 //
//An algorithm to compute quadratic functions.                 //
/////////////////////////////////////////////////////////////////
#include <iostream>
#include <cmath>
using namespace std;

void quadraticEquation(double, double, double&, double&); //& == reference character

int main() {
  while (true) {
    double x1, x2;
    double a, b, c;

    //input
    cout << "f(x) = ax" << static_cast<char>(253) << "+ bx + c" << endl; //with static_cast<char>(x)
    cout << "a = ";                                                      //you can paint ASCII-Codes
    cin >> a;
    cout << "b = ";
    cin >> b;
    cout << "c = ";
    cin >> c;

    //verification
    if (a != 1) {
      b /= a;
      c /= a;
    }

    //calculation
    quadraticEquation(b, c, x1, x2); //x1 and x2 are given by reference

    //output
    if (x1 == x2) {
      cout << "x1 = x2 (doppelt): " << x1 << endl;
    } else {
      cout << "x1 (plus): " << x1 << endl;
      cout << "x2 (minus): " << x2 << endl;
    }
    cout << endl;
    cin.get();
  }
}


void quadraticEquation(double p, double q, double& x_plus, double& x_minus) { //in this case x_plus and x_minus
  x_plus = -(p/2) + sqrt(pow(p/2, 2) - q);                                    //are aliases for x1 and x2
  x_minus = -(p/2) - sqrt(pow(p/2, 2) - q);
}

//Example values:
//1, 8, 15  -> -3, -5
//3, 5, 1   -> -0.232, -1.434
//1, 4, 4   -> -2
//1,-12, 35 -> 7, 5
//1, 2, -35 -> 5, -7
//1, -4, 4  -> 2
